package com.mi.rof.handler;

import com.mi.rof.entity.Result;
import com.mi.rof.entity.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zwq yyy
 */
@ControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler(value = SystemException.class)
    @ResponseBody
    public Result<String> systemExceptionHandler(SystemException e){
        return Result.fail(e.getErrorCode(),e.getErrorMsg());
    }


    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result<String> exceptionHandler(Exception e){
        log.error("默认异常处理",e);
        return Result.fail("-9999","系统异常");
    }


}
